<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!-- 重量段遍历td,分区遍历tr -->
<tr id="zhongliangduan">
	<td class="priceTd2">重量阶段说明</td>
	<c:forEach items="${requestScope.prices[0]}" var="weight" varStatus="ni">
		<td class="priceTd" id="weight${ni.index}"><input name="allPrices[0]" type="text" value="${weight}" class="required" size="5"/>
		</td>
	</c:forEach>
	<input type="hidden" name="allPrices" value="" /><!-- 导入价格需要 -->
</tr>
<tr id="huowuleixing">
	<td class="priceTd2">货物类型</td>
	<c:forEach items="${requestScope.prices[0]}" var="weight" varStatus="ni">
		<td class="priceTd"><select name="allPrices[1]" style="width: 70px;"><option value="WPX">包裹</option><option value="DOC">文件</option></select>
		</td>
	</c:forEach>
	<input type="hidden" name="allPrices" value="" /><!-- 导入价格需要 -->
</tr>
<tr id="szhongliang">
	<td class="priceTd2">最低重量</td>
	<c:forEach items="${requestScope.prices[0]}" var="weight" varStatus="ni">
	<td class="priceTd"><input name="allPrices[2]" type="text" value="0.5" class="number required" size="5"/>
	</td>
	</c:forEach>
	<input type="hidden" name="allPrices" value="" /><!-- 导入价格需要 -->
</tr>
<tr id="bzhongliang">
	<td class="priceTd2">最高重量</td>
	<c:forEach items="${requestScope.prices[0]}" var="weight" varStatus="ni">
	<td class="priceTd"><input name="allPrices[3]" type="text" value="0.5" class="number required" size="5"/>
	</td>
	</c:forEach>
	<input type="hidden" name="allPrices" value="" /><!-- 导入价格需要 -->
</tr>
<tr>
	<td class="priceTd2">计算方式</td>
	<c:forEach items="${requestScope.prices[0]}" var="weight" varStatus="ni">
	<td class="priceTd"><select name="allPrices[4]" style="width: 70px;"><option value="1">金额</option><option value="2">单价</option><option value="3">首重价格</option><option value="4">续重价格</option></select>
	</td>
	</c:forEach>
	<input type="hidden" name="allPrices" value="" /><!-- 导入价格需要 -->	
</tr>
<tr>
	<td class="priceTd2">单位重量</td>
	<c:forEach items="${requestScope.prices[0]}" var="weight" varStatus="ni">
	<td class="priceTd"><input name="allPrices[5]" type="text" value="0.5" class="number required" size="5"/>
	</td>
	</c:forEach>
	<input type="hidden" name="allPrices" value="" /><!-- 导入价格需要 -->
</tr>
<c:forEach items="${requestScope.epartitionsList}" var="epartition" varStatus="ni">
<tr>
	<td class="priceTd2">${epartition.partition_name}</td>
	<c:forEach items="${requestScope.prices[ni.index+1]}" var="weight" varStatus="nii">
		<td class="priceTd"><input name="allPrices[${ni.index+6}]" type="text" value="${weight}" class="number required" size="5"/>
		</td>
	</c:forEach>
	<input type="hidden" name="allPrices" value="" /><!-- 导入价格需要 -->
</tr>
</c:forEach>
<script type="text/javascript">
	(function(){
		var len = $("#priceTableBody tr:eq(0) td").length;
		var shou = -1;	//捕获 '首'的数值,用于编辑'续'的数值
		var zuigao = -1;	//前一个的最高数值
		var zld;
		for(var i=1;i<len;i++){
			zld = $("#priceTableBody_SP tr:eq(0) td:eq("+i+") input").val();
			//判断是否大货
			if(parseInt(zld) >= 21){
				$("#priceTableBody_SP tr:eq(5) td:eq("+i+") input").attr("value",$("#channelBcarry_SP").val());
			}else{
				$("#priceTableBody_SP tr:eq(5) td:eq("+i+") input").attr("value",$("#channelScarry_SP").val());
			}
			var cc;
			if(zld.indexOf('-') != -1){
				cc = 1;
				$("#priceTableBody_SP tr:eq(4) td:eq("+i+") select").attr("value",2);
			}else if( zld.indexOf('以上') != -1){
				cc = 2;
				$("#priceTableBody_SP tr:eq(4) td:eq("+i+") select").attr("value",2);
			}else if(zld.indexOf('首') != -1){
				cc = 3;
				$("#priceTableBody_SP tr:eq(4) td:eq("+i+") select").attr("value",3);
			}else if(zld.indexOf('续') != -1){
				cc = 4;
				$("#priceTableBody_SP tr:eq(4) td:eq("+i+") select").attr("value",4);
			}else if(zld.indexOf('≥') != -1){
				cc = 6;
				$("#priceTableBody_SP tr:eq(4) td:eq("+i+") select").attr("value",2);
			}else{
				cc = 5;
				$("#priceTableBody_SP tr:eq(4) td:eq("+i+") select").attr("value",1);
			}
			
			if(i==1){
				//第一列
				switch(cc){
					case 1:
						$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",zld.substring(0,zld.indexOf('-')));
						$("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").attr("value",zld.substring(zld.indexOf('-')+1,zld.indexOf('kg')==-1?zld.length:zld.indexOf('kg')));
						zuigao = $("#priceTableBody tr:eq(3) td:eq("+i+") input").val();	//重复
						break;
					case 2:
						var yishang = zhuanhuan(zld);
						$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",yishang);
						$("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").attr("value",9000);
						break;
					case 3:
						shou = zhuanhuan(zld);
						$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",0);
						$("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").attr("value",shou);
						$("#priceTableBody_SP tr:eq(5) td:eq("+i+") input").attr("value",shou);
						zuigao = $("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").val();	//重复
						break;
					case 5:
						$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",0);
						$("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").attr("value",zld);
						zuigao = $("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").val();	//重复
						break;
					case 6:
						$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",0);
						$("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").attr("value",zhuanhuan(zld));
						zuigao = zhuanhuan(zld);
						break;
					}
			}else{
				//非第一列
				switch(cc){
					case 1:
						$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",zld.substring(0,zld.indexOf('-')));
						$("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").attr("value",zld.substring(zld.indexOf('-')+1,zld.indexOf('kg')==-1?zld.length:zld.indexOf('kg')));
						zuigao = $("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").val();	//重复
						if($("#priceTableBody_SP tr:eq(0) td:eq("+(i-1)+") input").val().indexOf('续') != -1){
							//前一个'续'
							$("#priceTableBody_SP tr:eq(3) td:eq("+(i-1)+") input").attr("value",$("#priceTableBody tr:eq(2) td:eq("+i+") input").val());
						}
						break;
					case 2:
						var yishang = zhuanhuan(zld);
						$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",yishang);
						$("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").attr("value",9000);
						if($("#priceTableBody_SP tr:eq(0) td:eq("+(i-1)+") input").val().indexOf('续') != -1){
							//前一个'续'
							$("#priceTableBody_SP tr:eq(3) td:eq("+(i-1)+") input").attr("value",yishang);
						}
						break;
					case 3:
						shou = zhuanhuan(zld);
						$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",shou);
						$("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").attr("value",shou);
						$("#priceTableBody_SP tr:eq(5) td:eq("+i+") input").attr("value",shou);
						zuigao = $("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").val();	//重复
						if($("#priceTableBody_SP tr:eq(0) td:eq("+(i-1)+") input").val().indexOf('首') != -1){
							//前一个'首'是文件
							$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",0);
							$("#priceTableBody_SP tr:eq(1) td:eq("+(i-1)+") select").attr("value","DOC");
						}else if($("#priceTableBody_SP tr:eq(0) td:eq("+(i-1)+") input").val().indexOf('续') != -1){
							//前一个'续'
							$("#priceTableBody_SP tr:eq(3) td:eq("+(i-1)+") input").attr("value",shou);
						}
						break;
					case 4:
						$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",zuigao);
						break;
					case 5:
						$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",zuigao);
						$("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").attr("value",zld);
						zuigao = $("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").val();	//重复
						if($("#priceTableBody_SP tr:eq(0) td:eq("+(i-1)+") input").val().indexOf('续') != -1){
							//前一个'续'
							$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",zld-0.5);
							$("#priceTableBody_SP tr:eq(3) td:eq("+(i-1)+") input").attr("value",zld-0.5);
						}
						break;
					case 6:
						$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",zuigao);
						$("#priceTableBody_SP tr:eq(3) td:eq("+i+") input").attr("value",zhuanhuan(zld));
						zuigao = zhuanhuan(zld);
						if($("#priceTableBody_SP tr:eq(0) td:eq("+(i-1)+") input").val().indexOf('续') != -1){
							//前一个'续'
							$("#priceTableBody_SP tr:eq(2) td:eq("+i+") input").attr("value",zhuanhuan(zld)-0.5);
							$("#priceTableBody_SP tr:eq(3) td:eq("+(i-1)+") input").attr("value",zhuanhuan(zld)-0.5);
						}
						break;
				}
			}
			
		}
		
	})();
</script>